﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing.Drawing2D;

namespace 屏幕保护
{
    public partial class Form1 : Form
    {
        int shijian=0;
        int[] x;
        int[] y;
        int i = 0,ks,kj;
        int geshu = 6;
        Point[] r; 
       Random ra = new Random();
        public Form1()
        {
           InitializeComponent();
        }
        Bitmap bmp;
        private void shengcheng(int geshu)
        {
            Random ra = new Random();
            x=new int [geshu];
            y = new int[geshu];
            int k=10;
        r=new Point[geshu];
        for (int j = 0; j < geshu; j++)
        {
            ks = 8+ra.Next(2,4);
            kj = 8+ra.Next(4,6);
            x[j] = ks;
            y[j] = kj;
            r[j].X = k;
            r[j].Y = k;
           // k += 150;
        }
        }
        private void panduan(int geshu)
        {
            for (int j = 0; j < geshu; j++)
                if (j * 60 < i)
                    r[j] = new Point(r[j].X + x[j], r[j].Y - y[j]);//更新泡泡的位置
            for (int j = 0; j < geshu; j++)

                if (j * 60 < (i - 59))
                {
                    for (int k = j + 1; k < geshu; k++)

                        if ((r[j].X - r[k].X) * (r[j].X - r[k].X) + (r[j].Y - r[k].Y) * (r[j].Y - r[k].Y) <= 40000)
                        {

                            if (r[j].X > 0) x[j] = -x[j];
                            if (r[j].Y > 0) y[j] = -y[j];
                            if (r[k].X > 0) x[k] = -x[k];
                            if (r[k].Y > 0) y[k] = -y[k];

                        }
                }

            for (int j = 0; j < geshu; j++)
                if (j * 60 < i)
                {
                    if (r[j].X <= 0) x[j] = -x[j];
                    if (r[j].Y <= 0) y[j] = -y[j];
                    if (r[j].X >= 1720) x[j] = -x[j];
                    if (r[j].Y >= 880) y[j] = -y[j];
                }
            
            i++;
            Random ra = new Random();
            Image[] m = new Image[3];
            Image[] n = new Image[5];
            Image[] m1 = new Image[geshu];
            Image[] n1 = new Image[geshu];
            m[0] = Image.FromFile(@"C:\Users\Administrator\Desktop\Debug\images\ch0.png");
            m[1] = Image.FromFile(@"C:\Users\Administrator\Desktop\Debug\images\ch1.png");
            m[2] = Image.FromFile(@"C:\Users\Administrator\Desktop\Debug\images\ch2.png");
            n[0] = Image.FromFile(@"C:\Users\Administrator\Desktop\Debug\images\pian1.png");
            n[1] = Image.FromFile(@"C:\Users\Administrator\Desktop\Debug\images\pian2.png");
            n[2] = Image.FromFile(@"C:\Users\Administrator\Desktop\Debug\images\pian3.png");
            n[3] = Image.FromFile(@"C:\Users\Administrator\Desktop\Debug\images\pian4.png");
            n[4] = Image.FromFile(@"C:\Users\Administrator\Desktop\Debug\images\pian5.png");


            Bitmap xuni = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);
            Graphics ig = Graphics.FromImage(xuni);
            ig.Clear(BackColor);
            Graphics g = this.CreateGraphics();
            //if(i%10==0)

            for (int j = 0; j < geshu; j++)
            {

                m1[j] = m[ra.Next(3)];//随机要生成个数的泡泡颜色

            }

            if (geshu < 5)
                for (int j = 0; j < geshu; j++)
                    n1[j] = n[j];
            else
                for (int j = 0; j < geshu; j++)
                    if (j < 5)
                        n1[j] = n[j];
                    else
                        n1[j] = n[3];

            for (int j = 0; j < geshu; j++)
                if (j * 60 < i)
                {
                    ig.DrawImage(m1[j], r[j].X, r[j].Y, 200, 200);
                    ig.DrawImage(n1[j], r[j].X + 25, r[j].Y + 25, 140, 140);
                }
            g.DrawImage(xuni, 0, 0);

            /* //this.Refresh();
             Graphics g1 = this.CreateGraphics();
             g1.Clear(BackColor);
             i++;
             if (i == 20)
             {
                 i = 0;
                 i1++;
                 i2++;
                 i3++;
                 i4++;
             }
             Brush my = new SolidBrush(Color.Red);

             //LinearGradientBrush ll = new LinearGradientBrush(r[0].X, r[0].Y, 200, 200, color[i1], color[i2], LinearGradientMode.BackwardDiagonal);
             Pen pen = new Pen(Color.Red,1);
             if (i1 == 7) i1 = 0;
                 //g1.FillEllipse(new SolidBrush(color[i1]), r[0].X, r[0].Y, 200, 200);
             g1.DrawEllipse(new Pen(color[i1],10),r[0].X,r[0].Y,200,200);
             if (i2 == 7) i2 = 0;
             g1.DrawEllipse(new Pen(color[i2], 10), r[1].X, r[1].Y, 200, 200);
             if (i3 == 7) i3 = 0;
             g1.DrawEllipse(new Pen(color[i3], 10), r[2].X, r[2].Y, 200, 200);
             if (i4 == 7) i4 = 0;
             g1.DrawEllipse(new Pen(color[i4], 10), r[3].X, r[3].Y, 200, 200);
             if (i4 == 7) i4 = 0;
             g1.DrawEllipse(new Pen(color[i4], 10), r[4].X, r[4].Y, 200, 200);
             if (i4 == 7) i4 = 0;
             g1.DrawEllipse(new Pen(color[i2], 10), r[5].X, r[5].Y, 200, 200);*/
        }
        private void Form1_Paint(object  sender, PaintEventArgs e)
        {
            
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            panduan(geshu);
            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            shengcheng(geshu);
           /* for (int j = 0; j < 6; j++)
            {
                int l = ra.Next(100+100 * j);
                int m = ra.Next(100+80*j);
                r[j].X=l;
                r[j].Y = m;
            }*/
            
            //Color.FromArgb(0);
            //this.Opacity = 0.4;
           /*  int x1, y1,x2,x2;
            for (int j = 1; j < 20; i++)
            {
               ks += 50;
                x1 = ra.Next(ks);
                y1 = ra.Next(ks);
                if (x > 50 && y > 50)
                {
                    r[j].X = x;
                    r[j].Y = y;
                }
            }*/
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            this.Close();
        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            this.Close();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            shijian += 1;
            
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            this.Close();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        
}
    }

